package capricornus.components.utils
{
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.Sprite;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;

	public class FilterUtils
	{
		public static function setEnable( displayObject:DisplayObject, enable:Boolean ):void
		{
			if( enable )
			{
				displayObject.filters = null;
			}
			else
			{
				displayObject.filters = getGrayFilter();
			}
			if( displayObject is InteractiveObject )
			{
				InteractiveObject(displayObject).mouseEnabled = enable;
			}
			if( displayObject is Sprite )
			{
				Sprite(displayObject).mouseChildren = enable;
			}
		}
		
		public static function gray( dis:DisplayObject ):void
		{
			dis.filters = getGrayFilter();
		}
		
		public static function getSelectedFilter():Array
		{
			return [new GlowFilter(0x00ffcc, 1, 5, 5, 2)];
		}
		
		public static function getShineFilter( k:int=20 ):Array
		{
			var arr:Array = [1,0,0,0,k,0,1,0,0,k,0,0,1,0,k,0,0,0,1,0];
			return [new ColorMatrixFilter(arr)];
		}
		
		public static function getRedGlowFilter(len:int=4):Array
		{
			return [new GlowFilter( 0xff0000, 1, len, len, 2, 1 )];
		}
		
		public static function getGoldenGlowFilter():Array
		{
			return [new GlowFilter( 0xff9900, 1, 4, 4, 2, 1 )];
		}
		
		public static function getGreenGlowFilter():Array
		{
			return [new GlowFilter( 0x00ff00, 1, 4, 4, 2, 1 )];
		}
		
		public static function getBlueGlowFilter():Array
		{
			return [new GlowFilter( 0x66CCCC, 1, 4, 4, 2, 1 )];
		}
		
		public static function getBlackGlowFilter():Array
		{
			return [new GlowFilter( 0, 1, 2, 2, 7 )];
		}
		
		public static function getGrayFilter():Array
		{
			var k:Number = 1/3;
			return [new ColorMatrixFilter([k, k, k, 0, 0, k, k, k, 0, 0, k, k, k, 0, 0, 0, 0, 0, 1, 0])];
		}
	}
}